<?php

namespace app\api\validate\user;

use think\Validate;

class User extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */	
	protected $rule = [
	    'code|授权码' => 'require',
        'state|授权项' => 'require',
        'nickname|昵称' => 'require|max:10',
        'headimg_url|头像' => 'require|url'
    ];
    
    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */	
    protected $message = [
        'state.in' => '授权项不在范围内'
    ];

    /**
     * 定义场景
     * @var []
     */
    protected $scene = [
        'info' => ['nickname','headimg_url']
    ];

    /**
     * 定义授权场景验证
     * @return $this
     */
    public function sceneOauth2()
    {
        $stateList = array_keys(config('secret.'));
        return $this->only(['code','state'])
            ->append('state', 'in:'.implode(',', $stateList));
    }

}
